home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual BASIC 5.0 (Ent. Edition) / Vb5ent Extractor.EXE / VB / SAMPLES / COMPTOOL / MSCOMM / VBTERM.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-09-16  |  31.5 KB  |  928 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.0#0"; "comdlg32.ocx"
  3. Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.0#0"; "mscomm32.ocx"
  4. Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.0#0"; "comctl32.ocx"
  5. Begin VB.Form frmTerminal 
  6.    Caption         =   "Visual Basic Terminal"
  7.    ClientHeight    =   4935
  8.    ClientLeft      =   2940
  9.    ClientTop       =   2055
  10.    ClientWidth     =   7155
  11.    ForeColor       =   &H00000000&
  12.    Icon            =   "vbterm.frx":0000
  13.    LinkMode        =   1  'Source
  14.    LinkTopic       =   "Form1"
  15.    ScaleHeight     =   4935
  16.    ScaleWidth      =   7155
  17.    Begin VB.Timer Timer2 
  18.       Enabled         =   0   'False
  19.       Interval        =   2000
  20.       Left            =   210
  21.       Top             =   3645
  22.    End
  23.    Begin VB.TextBox txtTerm 
  24.       Height          =   3690
  25.       Left            =   1245
  26.       MultiLine       =   -1  'True
  27.       ScrollBars      =   3  'Both
  28.       TabIndex        =   3
  29.       Top             =   1140
  30.       Width           =   5790
  31.    End
  32.    Begin ComctlLib.Toolbar tbrToolBar 
  33.       Align           =   1  'Align Top
  34.       Height          =   390
  35.       Left            =   0
  36.       TabIndex        =   1
  37.       Top             =   0
  38.       Width           =   7155
  39.       _ExtentX        =   12621
  40.       _ExtentY        =   688
  41.       ButtonWidth     =   609
  42.       ButtonHeight    =   582
  43.       ImageList       =   "ImageList1"
  44.       BeginProperty Buttons {0713E452-850A-101B-AFC0-4210102A8DA7} 
  45.          NumButtons      =   10
  46.          BeginProperty Button1 {0713F354-850A-101B-AFC0-4210102A8DA7} 
  47.             Style           =   3
  48.             Value           =   1
  49.             MixedState      =   -1  'True
  50.          EndProperty
  51.          BeginProperty Button2 {0713F354-850A-101B-AFC0-4210102A8DA7} 
  52.             Key             =   "OpenLogFile"
  53.             Description     =   "Open Log File..."
  54.             Object.ToolTipText     =   "Open Log File..."
  55.             ImageIndex      =   1
  56.          EndProperty
  57.          BeginProperty Button3 {0713F354-850A-101B-AFC0-4210102A8DA7} 
  58.             Enabled         =   0   'False
  59.             Key             =   "CloseLogFile"
  60.             Description     =   "Close Log File"
  61.             Object.ToolTipText     =   "Close Log File"
  62.             ImageIndex      =   2
  63.          EndProperty
  64.          BeginProperty Button4 {0713F354-850A-101B-AFC0-4210102A8DA7} 
  65.             Style           =   3
  66.             Value           =   1
  67.             MixedState      =   -1  'True
  68.          EndProperty
  69.          BeginProperty Button5 {0713F354-850A-101B-AFC0-4210102A8DA7} 
  70.             Key             =   "DialPhoneNumber"
  71.             Description     =   "Dial Phone Number..."
  72.             Object.ToolTipText     =   "Dial Phone Number..."
  73.             ImageIndex      =   3
  74.          EndProperty
  75.          BeginProperty Button6 {0713F354-850A-101B-AFC0-4210102A8DA7} 
  76.             Enabled         =   0   'False
  77.             Key             =   "HangUpPhone"
  78.             Description     =   "Hang Up Phone"
  79.             Object.ToolTipText     =   "Hang Up Phone"
  80.             ImageIndex      =   4
  81.          EndProperty
  82.          BeginProperty Button7 {0713F354-850A-101B-AFC0-4210102A8DA7} 
  83.             Style           =   3
  84.             Value           =   1
  85.             MixedState      =   -1  'True
  86.          EndProperty
  87.          BeginProperty Button8 {0713F354-850A-101B-AFC0-4210102A8DA7} 
  88.             Key             =   "Properties"
  89.             Description     =   "Properties..."
  90.             Object.ToolTipText     =   "Properties..."
  91.             ImageIndex      =   5
  92.          EndProperty
  93.          BeginProperty Button9 {0713F354-850A-101B-AFC0-4210102A8DA7} 
  94.             Style           =   3
  95.             Value           =   1
  96.             MixedState      =   -1  'True
  97.          EndProperty
  98.          BeginProperty Button10 {0713F354-850A-101B-AFC0-4210102A8DA7} 
  99.             Enabled         =   0   'False
  100.             Key             =   "TransmitTextFile"
  101.             Description     =   "Transmit Text File..."
  102.             Object.ToolTipText     =   "Transmit Text File..."
  103.             ImageIndex      =   6
  104.          EndProperty
  105.       EndProperty
  106.       MouseIcon       =   "vbterm.frx":030A
  107.       Begin VB.Frame Frame1 
  108.          BorderStyle     =   0  'None
  109.          Caption         =   "Frame1"
  110.          Height          =   240
  111.          Left            =   4000
  112.          TabIndex        =   2
  113.          Top             =   75
  114.          Width           =   240
  115.          Begin VB.Image imgConnected 
  116.             Height          =   240
  117.             Left            =   0
  118.             Picture         =   "vbterm.frx":0326
  119.             Stretch         =   -1  'True
  120.             ToolTipText     =   "Toggles Port"
  121.             Top             =   0
  122.             Width           =   240
  123.          End
  124.          Begin VB.Image imgNotConnected 
  125.             Height          =   240
  126.             Left            =   0
  127.             Picture         =   "vbterm.frx":0470
  128.             Stretch         =   -1  'True
  129.             ToolTipText     =   "Toggles Port"
  130.             Top             =   0
  131.             Width           =   240
  132.          End
  133.       End
  134.    End
  135.    Begin VB.Timer Timer1 
  136.       Enabled         =   0   'False
  137.       Interval        =   1000
  138.       Left            =   165
  139.       Top             =   1815
  140.    End
  141.    Begin MSCommLib.MSComm MSComm1 
  142.       Left            =   45
  143.       Top             =   510
  144.       _ExtentX        =   1005
  145.       _ExtentY        =   1005
  146.       DTREnable       =   -1  'True
  147.       NullDiscard     =   -1  'True
  148.       RThreshold      =   1
  149.       RTSEnable       =   -1  'True
  150.       SThreshold      =   1
  151.       InputMode       =   1
  152.    End
  153.    Begin MSComDlg.CommonDialog OpenLog 
  154.       Left            =   105
  155.       Top             =   1170
  156.       _ExtentX        =   847
  157.       _ExtentY        =   847
  158.       DefaultExt      =   "LOG"
  159.       FileName        =   "Open Communications Log File"
  160.       Filter          =   "Log File (*.log)|*.log;"
  161.       FilterIndex     =   501
  162.       FontSize        =   9.02458e-38
  163.    End
  164.    Begin ComctlLib.StatusBar sbrStatus 
  165.       Align           =   2  'Align Bottom
  166.       Height          =   315
  167.       Left            =   0
  168.       TabIndex        =   0
  169.       Top             =   4620
  170.       Width           =   7155
  171.       _ExtentX        =   12621
  172.       _ExtentY        =   556
  173.       BeginProperty Panels {0713E89E-850A-101B-AFC0-4210102A8DA7} 
  174.          NumPanels       =   3
  175.          BeginProperty Panel1 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
  176.             AutoSize        =   2
  177.             Object.Width           =   2540
  178.             MinWidth        =   2540
  179.             Text            =   "Status:"
  180.             TextSave        =   "Status:"
  181.             Key             =   "Status"
  182.             Object.ToolTipText     =   "Communications Port Status"
  183.          EndProperty
  184.          BeginProperty Panel2 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
  185.             AutoSize        =   1
  186.             Object.Width           =   8310
  187.             MinWidth        =   2
  188.             Text            =   "Settings:"
  189.             TextSave        =   "Settings:"
  190.             Key             =   "Settings"
  191.             Object.ToolTipText     =   "Communications Port Settings"
  192.          EndProperty
  193.          BeginProperty Panel3 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
  194.             AutoSize        =   2
  195.             Object.Width           =   1244
  196.             MinWidth        =   1244
  197.             Key             =   "ConnectTime"
  198.             Object.ToolTipText     =   "Connect Time"
  199.          EndProperty
  200.       EndProperty
  201.       MouseIcon       =   "vbterm.frx":05BA
  202.    End
  203.    Begin ComctlLib.ImageList ImageList1 
  204.       Left            =   165
  205.       Top             =   2445
  206.       _ExtentX        =   1005
  207.       _ExtentY        =   1005
  208.       BackColor       =   -2147483643
  209.       ImageWidth      =   16
  210.       ImageHeight     =   16
  211.       MaskColor       =   12632256
  212.       BeginProperty Images {0713E8C2-850A-101B-AFC0-4210102A8DA7} 
  213.          NumListImages   =   6
  214.          BeginProperty ListImage1 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
  215.             Picture         =   "vbterm.frx":05D6
  216.             Key             =   ""
  217.          EndProperty
  218.          BeginProperty ListImage2 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
  219.             Picture         =   "vbterm.frx":08F0
  220.             Key             =   ""
  221.          EndProperty
  222.          BeginProperty ListImage3 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
  223.             Picture         =   "vbterm.frx":0C0A
  224.             Key             =   ""
  225.          EndProperty
  226.          BeginProperty ListImage4 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
  227.             Picture         =   "vbterm.frx":0F24
  228.             Key             =   ""
  229.          EndProperty
  230.          BeginProperty ListImage5 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
  231.             Picture         =   "vbterm.frx":123E
  232.             Key             =   ""
  233.          EndProperty
  234.          BeginProperty ListImage6 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
  235.             Picture         =   "vbterm.frx":1558
  236.             Key             =   ""
  237.          EndProperty
  238.       EndProperty
  239.    End
  240.    Begin VB.Menu mnuFile 
  241.       Caption         =   "&File"
  242.       Begin VB.Menu mnuOpenLog 
  243.          Caption         =   "&Open Log File..."
  244.       End
  245.       Begin VB.Menu mnuCloseLog 
  246.          Caption         =   "&Close Log File"
  247.          Enabled         =   0   'False
  248.       End
  249.       Begin VB.Menu M3 
  250.          Caption         =   "-"
  251.       End
  252.       Begin VB.Menu mnuSendText 
  253.          Caption         =   "&Transmit Text File..."
  254.          Enabled         =   0   'False
  255.       End
  256.       Begin VB.Menu Bar2 
  257.          Caption         =   "-"
  258.       End
  259.       Begin VB.Menu mnuFileExit 
  260.          Caption         =   "E&xit"
  261.       End
  262.    End
  263.    Begin VB.Menu mnuPort 
  264.       Caption         =   "&CommPort"
  265.       Begin VB.Menu mnuOpen 
  266.          Caption         =   "Port &Open"
  267.       End
  268.       Begin VB.Menu MBar1 
  269.          Caption         =   "-"
  270.       End
  271.       Begin VB.Menu mnuProperties 
  272.          Caption         =   "Properties..."
  273.       End
  274.    End
  275.    Begin VB.Menu mnuMSComm 
  276.       Caption         =   "&MSComm"
  277.       Begin VB.Menu mnuInputLen 
  278.          Caption         =   "&InputLen..."
  279.       End
  280.       Begin VB.Menu mnuRThreshold 
  281.          Caption         =   "&RThreshold..."
  282.       End
  283.       Begin VB.Menu mnuSThreshold 
  284.          Caption         =   "&SThreshold..."
  285.       End
  286.       Begin VB.Menu mnuParRep 
  287.          Caption         =   "P&arityReplace..."
  288.       End
  289.       Begin VB.Menu mnuDTREnable 
  290.          Caption         =   "&DTREnable"
  291.       End
  292.       Begin VB.Menu Bar3 
  293.          Caption         =   "-"
  294.       End
  295.       Begin VB.Menu mnuHCD 
  296.          Caption         =   "&CDHolding..."
  297.       End
  298.       Begin VB.Menu mnuHCTS 
  299.          Caption         =   "CTSH&olding..."
  300.       End
  301.       Begin VB.Menu mnuHDSR 
  302.          Caption         =   "DSRHo&lding..."
  303.       End
  304.    End
  305.    Begin VB.Menu mnuCall 
  306.       Caption         =   "C&all"
  307.       Begin VB.Menu mnuDial 
  308.          Caption         =   "&Dial Phone Number..."
  309.       End
  310.       Begin VB.Menu mnuHangUp 
  311.          Caption         =   "&Hang Up Phone"
  312.          Enabled         =   0   'False
  313.       End
  314.    End
  315. Attribute VB_Name = "frmTerminal"
  316. Attribute VB_Base = "0{3E2D207C-D67B-11CF-9BF3-00AA002FFD8F}"
  317. Attribute VB_GlobalNameSpace = False
  318. Attribute VB_Creatable = False
  319. Attribute VB_TemplateDerived = False
  320. Attribute VB_PredeclaredId = True
  321. Attribute VB_Exposed = False
  322. '--------------------------------------------------
  323. ' VBTerm - This is a demonstration program for the MSComm
  324. ' communications ActiveX control.
  325. ' Copyright (c) 1994, Crescent Software, Inc.
  326. ' by Don Malin and Carl Franklin.
  327. ' Updated by Mike Maddox
  328. '--------------------------------------------------
  329. Option Explicit
  330.                         
  331. Dim Ret As Integer      ' Scratch integer.
  332. Dim Temp As String      ' Scratch string.
  333. Dim hLogFile As Integer ' Handle of open log file.
  334. Dim StartTime As Date   ' Stores starting time for port timer
  335. Private Sub Form_Load()
  336.     Dim CommPort As String, Handshaking As String, Settings As String
  337.         
  338.     On Error Resume Next
  339.     ' Set the default color for the terminal
  340.     txtTerm.SelLength = Len(txtTerm)
  341.     txtTerm.SelText = ""
  342.     txtTerm.ForeColor = vbBlue
  343.        
  344.     ' Set Title
  345.     App.Title = "Visual Basic Terminal"
  346.     ' Set up status indicator light
  347.     imgNotConnected.ZOrder
  348.        
  349.     ' Center Form
  350.     frmTerminal.Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 2
  351.     ' Load Registry Settings
  352.     Settings = GetSetting(App.Title, "Properties", "Settings", "") ' frmTerminal.MSComm1.Settings]\
  353.     If Settings <> "" Then
  354.         MSComm1.Settings = Settings
  355.         If Err Then
  356.             MsgBox Error$, 48
  357.             Exit Sub
  358.         End If
  359.     End If
  360.     CommPort = GetSetting(App.Title, "Properties", "CommPort", "") ' frmTerminal.MSComm1.CommPort
  361.     If CommPort <> "" Then MSComm1.CommPort = CommPort
  362.     Handshaking = GetSetting(App.Title, "Properties", "Handshaking", "") 'frmTerminal.MSComm1.Handshaking
  363.     If Handshaking <> "" Then
  364.         MSComm1.Handshaking = Handshaking
  365.         If Err Then
  366.             MsgBox Error$, 48
  367.             Exit Sub
  368.         End If
  369.     End If
  370.     Echo = GetSetting(App.Title, "Properties", "Echo", "") ' Echo
  371.     On Error GoTo 0
  372. End Sub
  373. Private Sub Form_Resize()
  374.    ' Resize the Term (display) control
  375.    txtTerm.Move 0, tbrToolBar.Height, frmTerminal.ScaleWidth, frmTerminal.ScaleHeight - sbrStatus.Height - tbrToolBar.Height
  376.    ' Position the status indicator light
  377.    Frame1.Left = ScaleWidth - Frame1.Width * 1.5
  378. End Sub
  379. Private Sub Form_Unload(Cancel As Integer)
  380.     Dim Counter As Long
  381.     If MSComm1.PortOpen Then
  382.        ' Wait 10 seconds for data to be transmitted.
  383.        Counter = Timer + 10
  384.        Do While MSComm1.OutBufferCount
  385.           Ret = DoEvents()
  386.           If Timer > Counter Then
  387.              Select Case MsgBox("Data cannot be sent", 34)
  388.                 ' Cancel.
  389.                 Case 3
  390.                    Cancel = True
  391.                    Exit Sub
  392.                 ' Retry.
  393.                 Case 4
  394.                    Counter = Timer + 10
  395.                 ' Ignore.
  396.                 Case 5
  397.                    Exit Do
  398.              End Select
  399.           End If
  400.        Loop
  401.        MSComm1.PortOpen = 0
  402.     End If
  403.     ' If the log file is open, flush and close it.
  404.     If hLogFile Then mnuCloseLog_Click
  405.     End
  406. End Sub
  407. Private Sub imgConnected_Click()
  408.     ' Call the mnuOpen_Click routine to toggle connect and disconnect
  409.     Call mnuOpen_Click
  410. End Sub
  411. Private Sub imgNotConnected_Click()
  412.     ' Call the mnuOpen_Click routine to toggle connect and disconnect
  413.     Call mnuOpen_Click
  414. End Sub
  415. Private Sub mnuCloseLog_Click()
  416.     ' Close the log file.
  417.     Close hLogFile
  418.     hLogFile = 0
  419.     mnuOpenLog.Enabled = True
  420.     tbrToolBar.Buttons("OpenLogFile").Enabled = True
  421.     mnuCloseLog.Enabled = False
  422.     tbrToolBar.Buttons("CloseLogFile").Enabled = False
  423.     frmTerminal.Caption = "Visual Basic Terminal"
  424. End Sub
  425. Private Sub mnuDial_Click()
  426.     On Local Error Resume Next
  427.     Static Num As String
  428.     Num = "1-206-936-6735" ' This is the MSDN phone number
  429.     ' Get a number from the user.
  430.     Num = InputBox$("Enter Phone Number:", "Dial Number", Num)
  431.     If Num = "" Then Exit Sub
  432.     ' Open the port if it isn't already open.
  433.     If Not MSComm1.PortOpen Then
  434.        mnuOpen_Click
  435.        If Err Then Exit Sub
  436.     End If
  437.       
  438.     ' Enable hang up button and menu item
  439.     mnuHangUp.Enabled = True
  440.     tbrToolBar.Buttons("HangUpPhone").Enabled = True
  441.               
  442.     ' Dial the number.
  443.     MSComm1.Output = "ATDT" & Num & vbCrLf
  444.     ' Start the port timer
  445.     StartTiming
  446. End Sub
  447. ' Toggle the DTREnabled property.
  448. Private Sub mnuDTREnable_Click()
  449.     ' Toggle DTREnable property
  450.     MSComm1.DTREnable = Not MSComm1.DTREnable
  451.     mnuDTREnable.Checked = MSComm1.DTREnable
  452. End Sub
  453. Private Sub mnuFileExit_Click()
  454.     ' Use Form_Unload since it has code to check for unsent data and an open log file.
  455.     Form_Unload Ret
  456. End Sub
  457. ' Toggle the DTREnable property to hang up the line.
  458. Private Sub mnuHangup_Click()
  459.     On Error Resume Next
  460.     MSComm1.Output = "ATH"      ' Send hangup string
  461.     Ret = MSComm1.DTREnable     ' Save the current setting.
  462.     MSComm1.DTREnable = True    ' Turn DTR on.
  463.     MSComm1.DTREnable = False   ' Turn DTR off.
  464.     MSComm1.DTREnable = Ret     ' Restore the old setting.
  465.     mnuHangUp.Enabled = False
  466.     tbrToolBar.Buttons("HangUpPhone").Enabled = False
  467.     ' If port is actually still open, then close it
  468.     If MSComm1.PortOpen Then MSComm1.PortOpen = False
  469.     ' Notify user of error
  470.     If Err Then MsgBox Error$, 48
  471.     mnuSendText.Enabled = False
  472.     tbrToolBar.Buttons("TransmitTextFile").Enabled = False
  473.     mnuHangUp.Enabled = False
  474.     tbrToolBar.Buttons("HangUpPhone").Enabled = False
  475.     mnuDial.Enabled = True
  476.     tbrToolBar.Buttons("DialPhoneNumber").Enabled = True
  477.     sbrStatus.Panels("Settings").Text = "Settings: "
  478.     ' Turn off indicator light and uncheck open menu
  479.     mnuOpen.Checked = False
  480.     imgNotConnected.ZOrder
  481.             
  482.     ' Stop the port timer
  483.     StopTiming
  484.     sbrStatus.Panels("Status").Text = "Status: "
  485.     On Error GoTo 0
  486. End Sub
  487. ' Display the value of the CDHolding property.
  488. Private Sub mnuHCD_Click()
  489.     If MSComm1.CDHolding Then
  490.         Temp = "True"
  491.     Else
  492.         Temp = "False"
  493.     End If
  494.     MsgBox "CDHolding = " + Temp
  495. End Sub
  496. ' Display the value of the CTSHolding property.
  497. Private Sub mnuHCTS_Click()
  498.     If MSComm1.CTSHolding Then
  499.         Temp = "True"
  500.     Else
  501.         Temp = "False"
  502.     End If
  503.     MsgBox "CTSHolding = " + Temp
  504. End Sub
  505. ' Display the value of the DSRHolding property.
  506. Private Sub mnuHDSR_Click()
  507.     If MSComm1.DSRHolding Then
  508.         Temp = "True"
  509.     Else
  510.         Temp = "False"
  511.     End If
  512.     MsgBox "DSRHolding = " + Temp
  513. End Sub
  514. ' This procedure sets the InputLen property, which determines how
  515. ' many bytes of data are read each time Input is used
  516. ' to retreive data from the input buffer.
  517. ' Setting InputLen to 0 specifies that
  518. ' the entire contents of the buffer should be read.
  519. Private Sub mnuInputLen_Click()
  520.     On Error Resume Next
  521.     Temp = InputBox$("Enter New InputLen:", "InputLen", Str$(MSComm1.InputLen))
  522.     If Len(Temp) Then
  523.         MSComm1.InputLen = Val(Temp)
  524.         If Err Then MsgBox Error$, 48
  525.     End If
  526. End Sub
  527. Private Sub mnuProperties_Click()
  528.   ' Show the CommPort properties form
  529.   frmProperties.Show vbModal
  530. End Sub
  531. ' Toggles the state of the port (open or closed).
  532. Private Sub mnuOpen_Click()
  533.     On Error Resume Next
  534.     Dim OpenFlag
  535.     MSComm1.PortOpen = Not MSComm1.PortOpen
  536.     If Err Then MsgBox Error$, 48
  537.     OpenFlag = MSComm1.PortOpen
  538.     mnuOpen.Checked = OpenFlag
  539.     mnuSendText.Enabled = OpenFlag
  540.     tbrToolBar.Buttons("TransmitTextFile").Enabled = OpenFlag
  541.         
  542.     If MSComm1.PortOpen Then
  543.         ' Enable dial button and menu item
  544.         mnuDial.Enabled = True
  545.         tbrToolBar.Buttons("DialPhoneNumber").Enabled = True
  546.         
  547.         ' Enable hang up button and menu item
  548.         mnuHangUp.Enabled = True
  549.         tbrToolBar.Buttons("HangUpPhone").Enabled = True
  550.         
  551.         imgConnected.ZOrder
  552.         sbrStatus.Panels("Settings").Text = "Settings: " & MSComm1.Settings
  553.         StartTiming
  554.     Else
  555.         ' Enable dial button and menu item
  556.         mnuDial.Enabled = True
  557.         tbrToolBar.Buttons("DialPhoneNumber").Enabled = True
  558.         
  559.         ' Disable hang up button and menu item
  560.         mnuHangUp.Enabled = False
  561.         tbrToolBar.Buttons("HangUpPhone").Enabled = False
  562.         
  563.         imgNotConnected.ZOrder
  564.         sbrStatus.Panels("Settings").Text = "Settings: "
  565.         StopTiming
  566.     End If
  567. End Sub
  568. Private Sub mnuOpenLog_Click()
  569.    Dim replace
  570.    On Error Resume Next
  571.    OpenLog.Flags = cdlOFNHideReadOnly Or cdlOFNExplorer
  572.    OpenLog.CancelError = True
  573.       
  574.    ' Get the log filename from the user.
  575.    OpenLog.DialogTitle = "Open Communications Log File"
  576.    OpenLog.Filter = "Log Files (*.LOG)|*.log|All Files (*.*)|*.*"
  577.    Do
  578.       OpenLog.Filename = ""
  579.       OpenLog.ShowOpen
  580.       If Err = cdlCancel Then Exit Sub
  581.       Temp = OpenLog.Filename
  582.       ' If the file already exists, ask if the user wants to overwrite the file or add to it.
  583.       Ret = Len(Dir$(Temp))
  584.       If Err Then
  585.          MsgBox Error$, 48
  586.          Exit Sub
  587.       End If
  588.       If Ret Then
  589.          replace = MsgBox("Replace existing file - " + Temp + "?", 35)
  590.       Else
  591.          replace = 0
  592.       End If
  593.    Loop While replace = 2
  594.    ' User clicked the Yes button, so delete the file.
  595.    If replace = 6 Then
  596.       Kill Temp
  597.       If Err Then
  598.          MsgBox Error$, 48
  599.          Exit Sub
  600.       End If
  601.    End If
  602.    ' Open the log file.
  603.    hLogFile = FreeFile
  604.    Open Temp For Binary Access Write As hLogFile
  605.    If Err Then
  606.       MsgBox Error$, 48
  607.       Close hLogFile
  608.       hLogFile = 0
  609.       Exit Sub
  610.    Else
  611.       ' Go to the end of the file so that new data can be appended.
  612.       Seek hLogFile, LOF(hLogFile) + 1
  613.    End If
  614.    frmTerminal.Caption = "Visual Basic Terminal - " + OpenLog.FileTitle
  615.    mnuOpenLog.Enabled = False
  616.    tbrToolBar.Buttons("OpenLogFile").Enabled = False
  617.    mnuCloseLog.Enabled = True
  618.    tbrToolBar.Buttons("CloseLogFile").Enabled = True
  619. End Sub
  620. ' This procedure sets the ParityReplace property, which holds the
  621. ' character that will replace any incorrect characters
  622. ' that are received because of a parity error.
  623. Private Sub mnuParRep_Click()
  624.     On Error Resume Next
  625.     Temp = InputBox$("Enter Replace Character", "ParityReplace", frmTerminal.MSComm1.ParityReplace)
  626.     frmTerminal.MSComm1.ParityReplace = Left$(Temp, 1)
  627.     If Err Then MsgBox Error$, 48
  628. End Sub
  629. ' This procedure sets the RThreshold property, which determines
  630. ' how many bytes can arrive at the receive buffer before the OnComm
  631. ' event is triggered and the CommEvent property is set to comEvReceive.
  632. Private Sub mnuRThreshold_Click()
  633.     On Error Resume Next
  634.     Temp = InputBox$("Enter New RThreshold:", "RThreshold", Str$(MSComm1.RThreshold))
  635.     If Len(Temp) Then
  636.         MSComm1.RThreshold = Val(Temp)
  637.         If Err Then MsgBox Error$, 48
  638.     End If
  639. End Sub
  640. ' The OnComm event is used for trapping communications events and errors.
  641. Private Static Sub MSComm1_OnComm()
  642.     Dim EVMsg$
  643.     Dim ERMsg$
  644.     ' Branch according to the CommEvent property.
  645.     Select Case MSComm1.CommEvent
  646.         ' Event messages.
  647.         Case comEvReceive
  648.             Dim Buffer As Variant
  649.             Buffer = MSComm1.Input
  650.             Debug.Print "Receive - " & StrConv(Buffer, vbUnicode)
  651.             ShowData txtTerm, (StrConv(Buffer, vbUnicode))
  652.         Case comEvSend
  653.         Case comEvCTS
  654.             EVMsg$ = "Change in CTS Detected"
  655.         Case comEvDSR
  656.             EVMsg$ = "Change in DSR Detected"
  657.         Case comEvCD
  658.             EVMsg$ = "Change in CD Detected"
  659.         Case comEvRing
  660.             EVMsg$ = "The Phone is Ringing"
  661.         Case comEvEOF
  662.             EVMsg$ = "End of File Detected"
  663.         ' Error messages.
  664.         Case comBreak
  665.             ERMsg$ = "Break Received"
  666.         Case comCDTO
  667.             ERMsg$ = "Carrier Detect Timeout"
  668.         Case comCTSTO
  669.             ERMsg$ = "CTS Timeout"
  670.         Case comDCB
  671.             ERMsg$ = "Error retrieving DCB"
  672.         Case comDSRTO
  673.             ERMsg$ = "DSR Timeout"
  674.         Case comFrame
  675.             ERMsg$ = "Framing Error"
  676.         Case comOverrun
  677.             ERMsg$ = "Overrun Error"
  678.         Case comRxOver
  679.             ERMsg$ = "Receive Buffer Overflow"
  680.         Case comRxParity
  681.             ERMsg$ = "Parity Error"
  682.         Case comTxFull
  683.             ERMsg$ = "Transmit Buffer Full"
  684.         Case Else
  685.             ERMsg$ = "Unknown error or event"
  686.     End Select
  687.     If Len(EVMsg$) Then
  688.         ' Display event messages in the status bar.
  689.         sbrStatus.Panels("Status").Text = "Status: " & EVMsg$
  690.                 
  691.         ' Enable timer so that the message in the status bar
  692.         ' is cleared after 2 seconds
  693.         Timer2.Enabled = True
  694.         
  695.     ElseIf Len(ERMsg$) Then
  696.         ' Display event messages in the status bar.
  697.         sbrStatus.Panels("Status").Text = "Status: " & ERMsg$
  698.         
  699.         ' Display error messages in an alert message box.
  700.         Beep
  701.         Ret = MsgBox(ERMsg$, 1, "Click Cancel to quit, OK to ignore.")
  702.         
  703.         ' If the user clicks Cancel (2)...
  704.         If Ret = 2 Then
  705.             MSComm1.PortOpen = False    ' Close the port and quit.
  706.         End If
  707.         
  708.         ' Enable timer so that the message in the status bar
  709.         ' is cleared after 2 seconds
  710.         Timer2.Enabled = True
  711.     End If
  712. End Sub
  713. Private Sub mnuSendText_Click()
  714.    Dim hSend, BSize, LF&
  715.    On Error Resume Next
  716.    mnuSendText.Enabled = False
  717.    tbrToolBar.Buttons("TransmitTextFile").Enabled = False
  718.    ' Get the text filename from the user.
  719.    OpenLog.DialogTitle = "Send Text File"
  720.    OpenLog.Filter = "Text Files (*.TXT)|*.txt|All Files (*.*)|*.*"
  721.    Do
  722.       OpenLog.CancelError = True
  723.       OpenLog.Filename = ""
  724.       OpenLog.ShowOpen
  725.       If Err = cdlCancel Then
  726.         mnuSendText.Enabled = True
  727.         tbrToolBar.Buttons("TransmitTextFile").Enabled = True
  728.         Exit Sub
  729.       End If
  730.       Temp = OpenLog.Filename
  731.       ' If the file doesn't exist, go back.
  732.       Ret = Len(Dir$(Temp))
  733.       If Err Then
  734.          MsgBox Error$, 48
  735.          mnuSendText.Enabled = True
  736.          tbrToolBar.Buttons("TransmitTextFile").Enabled = True
  737.          Exit Sub
  738.       End If
  739.       If Ret Then
  740.          Exit Do
  741.       Else
  742.          MsgBox Temp + " not found!", 48
  743.       End If
  744.    Loop
  745.    ' Open the log file.
  746.    hSend = FreeFile
  747.    Open Temp For Binary Access Read As hSend
  748.    If Err Then
  749.       MsgBox Error$, 48
  750.    Else
  751.       ' Display the Cancel dialog box.
  752.       CancelSend = False
  753.       frmCancelSend.Label1.Caption = "Transmitting Text File - " + Temp
  754.       frmCancelSend.Show
  755.       
  756.       ' Read the file in blocks the size of the transmit buffer.
  757.       BSize = MSComm1.OutBufferSize
  758.       LF& = LOF(hSend)
  759.       Do Until EOF(hSend) Or CancelSend
  760.          ' Don't read too much at the end.
  761.          If LF& - Loc(hSend) <= BSize Then
  762.             BSize = LF& - Loc(hSend) + 1
  763.          End If
  764.       
  765.          ' Read a block of data.
  766.          Temp = Space$(BSize)
  767.          Get hSend, , Temp
  768.       
  769.          ' Transmit the block.
  770.          MSComm1.Output = Temp
  771.          If Err Then
  772.             MsgBox Error$, 48
  773.             Exit Do
  774.          End If
  775.       
  776.          ' Wait for all the data to be sent.
  777.          Do
  778.             Ret = DoEvents()
  779.          Loop Until MSComm1.OutBufferCount = 0 Or CancelSend
  780.       Loop
  781.    End If
  782.    Close hSend
  783.    mnuSendText.Enabled = True
  784.    tbrToolBar.Buttons("TransmitTextFile").Enabled = True
  785.    CancelSend = True
  786.    frmCancelSend.Hide
  787. End Sub
  788. ' This procedure sets the SThreshold property, which determines
  789. ' how many characters (at most) have to be waiting
  790. ' in the output buffer before the CommEvent property
  791. ' is set to comEvSend and the OnComm event is triggered.
  792. Private Sub mnuSThreshold_Click()
  793.     On Error Resume Next
  794.     Temp = InputBox$("Enter New SThreshold Value", "SThreshold", Str$(MSComm1.SThreshold))
  795.     If Len(Temp) Then
  796.         MSComm1.SThreshold = Val(Temp)
  797.         If Err Then MsgBox Error$, 48
  798.     End If
  799. End Sub
  800. ' This procedure adds data to the Term control's Text property.
  801. ' It also filters control characters, such as BACKSPACE,
  802. ' carriage return, and line feeds, and writes data to
  803. ' an open log file.
  804. ' BACKSPACE characters delete the character to the left,
  805. ' either in the Text property, or the passed string.
  806. ' Line feed characters are appended to all carriage
  807. ' returns.  The size of the Term control's Text
  808. ' property is also monitored so that it never
  809. ' exceeds MAXTERMSIZE characters.
  810. Private Static Sub ShowData(Term As Control, Data As String)
  811.     On Error GoTo Handler
  812.     Const MAXTERMSIZE = 16000
  813.     Dim TermSize As Long, i
  814.     ' Make sure the existing text doesn't get too large.
  815.     TermSize = Len(Term.Text)
  816.     If TermSize > MAXTERMSIZE Then
  817.        Term.Text = Mid$(Term.Text, 4097)
  818.        TermSize = Len(Term.Text)
  819.     End If
  820.     ' Point to the end of Term's data.
  821.     Term.SelStart = TermSize
  822.     ' Filter/handle BACKSPACE characters.
  823.     Do
  824.        i = InStr(Data, Chr$(8))
  825.        If i Then
  826.           If i = 1 Then
  827.              Term.SelStart = TermSize - 1
  828.              Term.SelLength = 1
  829.              Data = Mid$(Data, i + 1)
  830.           Else
  831.              Data = Left$(Data, i - 2) & Mid$(Data, i + 1)
  832.           End If
  833.        End If
  834.     Loop While i
  835.     ' Eliminate line feeds.
  836.     Do
  837.        i = InStr(Data, Chr$(10))
  838.        If i Then
  839.           Data = Left$(Data, i - 1) & Mid$(Data, i + 1)
  840.        End If
  841.     Loop While i
  842.     ' Make sure all carriage returns have a line feed.
  843.     i = 1
  844.     Do
  845.        i = InStr(i, Data, Chr$(13))
  846.        If i Then
  847.           Data = Left$(Data, i) & Chr$(10) & Mid$(Data, i + 1)
  848.           i = i + 1
  849.        End If
  850.     Loop While i
  851.     ' Add the filtered data to the SelText property.
  852.     Term.SelText = Data
  853.     ' Log data to file if requested.
  854.     If hLogFile Then
  855.        i = 2
  856.        Do
  857.           Err = 0
  858.           Put hLogFile, , Data
  859.           If Err Then
  860.              i = MsgBox(Error$, 21)
  861.              If i = 2 Then
  862.                 mnuCloseLog_Click
  863.              End If
  864.           End If
  865.        Loop While i <> 2
  866.     End If
  867.     Term.SelStart = Len(Term.Text)
  868. Exit Sub
  869. Handler:
  870.     MsgBox Error$
  871.     Resume Next
  872. End Sub
  873. Private Sub Timer2_Timer()
  874. sbrStatus.Panels("Status").Text = "Status: "
  875. Timer2.Enabled = False
  876. End Sub
  877. ' Keystrokes trapped here are sent to the MSComm
  878. ' control where they are echoed back via the
  879. ' OnComm (comEvReceive) event, and displayed
  880. ' with the ShowData procedure.
  881. Private Sub txtTerm_KeyPress(KeyAscii As Integer)
  882.     ' If the port is opened...
  883.     If MSComm1.PortOpen Then
  884.         ' Send the keystroke to the port.
  885.         MSComm1.Output = Chr$(KeyAscii)
  886.         
  887.         ' Unless Echo is on, there is no need to
  888.         ' let the text control display the key.
  889.         ' A modem usually echos back a character
  890.         If Not Echo Then
  891.             ' Place position at end of terminal
  892.             txtTerm.SelStart = Len(txtTerm)
  893.             KeyAscii = 0
  894.         End If
  895.     End If
  896.      
  897. End Sub
  898. Private Sub tbrToolBar_ButtonClick(ByVal Button As ComctlLib.Button)
  899. Select Case Button.Key
  900. Case "OpenLogFile"
  901.     Call mnuOpenLog_Click
  902. Case "CloseLogFile"
  903.     Call mnuCloseLog_Click
  904. Case "DialPhoneNumber"
  905.     Call mnuDial_Click
  906. Case "HangUpPhone"
  907.     Call mnuHangup_Click
  908. Case "Properties"
  909.     Call mnuProperties_Click
  910. Case "TransmitTextFile"
  911.     Call mnuSendText_Click
  912. End Select
  913. End Sub
  914. Private Sub Timer1_Timer()
  915.     ' Display the Connect Time
  916.     sbrStatus.Panels("ConnectTime").Text = Format(Now - StartTime, "hh:nn:ss") & " "
  917. End Sub
  918. ' Call this function to start the Connect Time timer
  919. Private Sub StartTiming()
  920.     StartTime = Now
  921.     Timer1.Enabled = True
  922. End Sub
  923. ' Call this function to stop timing
  924. Private Sub StopTiming()
  925.     Timer1.Enabled = False
  926.     sbrStatus.Panels("ConnectTime").Text = ""
  927. End Sub
  928.